<?php
$dirList = explode ( '/', $_SERVER ['PHP_SELF'] );
$document_root = $_SERVER ["DOCUMENT_ROOT"];
require "$document_root/$dirList[1]/conf/conf.php";
$connMgr = new ConnManger ( $db_conf, $mem_conf );
$connMng = $connMgr->getConn_renren_nuo();
$admin_user_list = Rrn_admin_user_DAO::getList($connMng);
$page_groupId = GROUP_ADMIN_MNG;
$page_pageId = PAGE_ADMIN_MNG;
require "$document_root/$dirList[1]/mng/view/framepages/moudle_base.php";

$mode = $_GET["mode"];
$result="normal";

if($mode=="mode_del"){
        $admin_user_id = $_GET["admin_user_id"];
        $admin_user_record = Rrn_admin_user_DAO::getRecord($admin_user_id,$connMng);
        Rrn_admin_user_DAO::delete($admin_user_record,$connMng);
        $result = "succ_del";
        $admin_user_list = Rrn_admin_user_DAO::getList($connMng);
}

$needle = $_GET["needle"];
if($needle){
        $admin_user_list = Rrn_admin_user_DAO::getListByNeedle($needle,$connMng);
}
?>


<div class="main-content" id="admin_user_list">
        <div class="search-well">
                <form class="form-inline" style="margin-top: 0px;">
                        用户检索 &nbsp;<input class="input-xlarge form-control"
                                          placeholder="用户ID/用户名称" id="renren_nuo_Name" type="text"> &nbsp;
                        <button class="btn btn-default" type="button" id="searchButton">
                                <i class="fa fa-search"></i> 查找
                        </button>
                </form>
        </div>
        <table class="table">
                <thead>
                <tr>
                        <th>编号</th>
                        <th>用户ID</th>
                        <th>用户名称</th>
                        <th>用户级别</th>
                        <th>状态</th>
                        <th>创建日期</th>
                        <th>更改日期</th>
                        <th colspan="2">操作</th>
                        <th style="width: 3.5em;"></th>
                </tr>

                <?php
                        $i=1;
                        foreach($admin_user_list as $admin_user_list_record){
                                $admin_user_id = $admin_user_list_record->getId();
                                $admin_user_name = $admin_user_list_record->getName();
                                $admin_user_rank = $admin_user_list_record->getRank();
                                $admin_user_state = $admin_user_list_record->getState();
                                $admin_user_createDate = $admin_user_list_record->getCreatedate();
                                $admin_user_updateDate = $admin_user_list_record->getUpdatedate();
                                echo "
                                    <tr>
                                    <td>$i</td>
                                    <td>$admin_user_id</td>
                                    <td>$admin_user_name</td>
                                    <td>$admin_user_rank</td>
                                    <td>$admin_user_state</td>
                                    <td>$admin_user_createDate</td>
                                    <td>$admin_user_updateDate</td>       
                                    <td><button id='mode_alter' class=\"btn btn-danger\" onclick='fn_alter(\"$admin_user_id\")'>修改</button></td>
                                    <td><button id='mode_delete' class=\"btn btn-danger\" onclick='fn_del(\"$admin_user_id\")'>删除</button></td>
                                    
                                    </tr>                                    
                                    ";
                                $i++;
                        }

                ?>

                </thead>

        </table>
</div>

<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">

        needle = "<?php echo $needle?>";
        $('#searchButton').click(function(){
                needle = $('#renren_nuo_Name').val();
                window.location.href = "?needle="+needle;
        });
</script>

<script type="text/javascript">
        function fn_del(admin_user_id){
                var url;
                if(window.confirm("确认删除该用户吗？")){
                        url="?mode=mode_del&admin_user_id="+admin_user_id;
                        window.location.href=url;
                }
        }
        function fn_alter(admin_user_id){
                url="admin_user_mng_edit.php?mode=mode_alter&admin_user_id="+admin_user_id;
                window.location.href=url;
        }
        function init(){
                var result = "<?php echo $result ?>";
                if(result=="succ_del"){
                        alert("删除成功！");
                }
        }
</script>

